<!DOCTYPE html>
{% load static %}
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ article.title }} - {{ article.author }}</title>
    <style>
        /* CSS 样式可以根据需要自行添加 */
        /* 页面居中显示 */
        body {
            background-image: url("{% static 'img/myimg.jpg' %}");
            background-size: cover;
            background-repeat: no-repeat;
            background-attachment: fixed; /* 保持背景图固定不随滚动而移动 */
            background-position: center;
            display: flex;
            justify-content: center;
            align-items: center;
            font-family: Arial, sans-serif;
        }

        /* 整体容器 */
        .container {
            width: 80%; /* 调整宽度 */
            background-color: rgba(255, 255, 255, 0.6); /* 设置背景色并调整透明度 */
            backdrop-filter: blur(10px); /* 添加毛玻璃效果 */
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            margin-top: 50px; /* Add some space from top */
            {#align-items: center;#}
        }

        /* 导航栏 */
        .navbar {
            display: flex;
            justify-content: space-between;
            align-items: center;
            background-color: #999;
            color: white;
            padding: 10px 20px;
            border-radius: 20px;
        }
        .navbar button {
            color: white;
            background-color: transparent;
            border: none;
            cursor: pointer;
        }
        a {
            text-decoration: none;
            color: black;
        }

        h1 {
            text-align: center;
        }

        h2 {
            margin-top: 20px;
        }

        span {
            margin-right: 5px;
            background-color: #ddd;
            padding: 3px 5px;
            border-radius: 4px;
        }

        .centered {
            {#margin-bottom: 5px;#}
            text-align: center; /* Center align text */
        }

        div {
            background-color: rgba(255, 255, 255, 0.6);
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }

        form.comment{
            margin:20px 20px 20px 20px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            background: #50dfdb;
        }

        .postcom{
            margin:20px 20px 20px 20px;
            padding: 20px 20px 20px 20px;
        }

        .comment-input {
            height: 120px;
            width: 100%;
            /* 其他样式 */
        }

        .sub_btn {
            background-color: #add8e6; /* 浅蓝色 */
            border: none;
            color: white;
            padding: 8px 16px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
            margin-top: 10px; /* 根据需要调整间距 */
            margin-bottom: 10px; /* 根据需要调整间距 */
            float: right; /* 靠右浮动 */
        }

        /* 当鼠标悬停时 */
        .sub_btn:hover {
            background-color: #4682b4; /* 深蓝色 */
            cursor: pointer;
        }

        #markdownBody{
            margin-left:20px;
            margin-right:20px;
            text-align: left; /* 让内容左对齐 */
        }


    </style>
    <script src="{% static 'js/marked.min.js' %}"></script>

</head>
<body>
    <div class="container">
        <!-- 导航栏 -->
        <div class="navbar">
            <button><a href="/">首页</a></button>
            <button><a href="/blog/edit/">写博客</a></button>
            <!-- Add other navigation buttons as needed -->

{#            <!-- Example of Search Form -->#}
{#            <form action="{% url 'search_results' usrname=requested_user.username %}" method="GET">#}
{#                <input type="text" class="search" placeholder="Search for something!!!" name="query">#}
{#                <button type="submit">搜索</button>#}
{#            </form>#}

            <button><a href="/user/centre/{{ current_user }}">我的主页</a></button>
            {% if owner %}
            <button><a href="/blog/update/{{ article.aid }}/">编辑</a></button>
            {% endif %}
            <button><a href="/user/logout/">退出登录</a></button>
            <!-- Add other navigation buttons as needed -->
        </div>

        <!-- 文章 -->
        <h1>{{ article.title }}</h1>
        <p class="centered">作者：{{ article.author.nickname }}</p>
        <p class="centered">
            {% for tag in tags %}
                <span class="tags">{{ tag }}</span>
            {% endfor %}
        </p>
        <p class="centered">更新时间：{{ article.updatedAt }}</p>
        <div class="article-body" id="markdownBody">
            {{ article.body }}
        </div>
        <div class="postcom">
            <form method="POST" action="{% url 'blog:post_comment' article_id=article.aid %}" style="overflow: hidden;">
                {% csrf_token %}
                <!-- <textarea name="comment" class="comment-input">{{ form.comment }}</textarea> -->
                {{ form.comment }}
                <button class="sub_btn" type="submit" name="submit">评论</button>
            </form>
        </div>

        <!-- 评论 -->
        <h2>评论区</h2>
        <div>
            {% for comment in comments %}

                    <p>{{ comment.author.nickname }}: {{ comment.content }}</p>
            {% endfor %}
        </div>

    </div>

</body>

<script>
    // 获取 Markdown 源文本
    var markdownText = "{{ article.body|escapejs }}"; // 使用 |escapejs 过滤器以确保 JavaScript 安全
    // 转换为 HTML 并插入到相应的 div 中
    document.getElementById('markdownBody').innerHTML = marked(markdownText);
</script>
</html>


